package tests.cases {
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import org.flexunit.Assert;
	
	import tests.cases.DefaultTestCase;
	
	public class TestUserProfile extends DefaultTestCase {
		
		private var userProfileService:RemoteObject;
		
		[Before]
		public function setUp():void {
			
			userProfileService = new RemoteObject();
			userProfileService.destination = "amfphp";
			userProfileService.source = "UserProfileService";
		}
		
		[After]
		public function tearDown():void {
			
			userProfileService = null;
		}
		
		// ----------------------------------------------------------------
		// TEST SAVE USER STATUS
		// ----------------------------------------------------------------
		[Test(async,order=1)]
		public function testSaveUserStatus():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001",
				status: "Test Status Message"
			};
			
			var token:AsyncToken = userProfileService.saveUserStatus(argsVO.sessionID, argsVO.userUID, argsVO.status);
			runAsyncTest(token, argsVO, handleSaveUserStatus);
		}
		
		private function handleSaveUserStatus(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNull(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST SAVE BLOG POST
		// ----------------------------------------------------------------
		[Test(async,order=2)]
		public function testSaveBlogPost():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001",
				heading: "Test Blog Post",
				message: "This is a test blog post."
			};
			
			var token:AsyncToken = userProfileService.saveBlogPost(argsVO.sessionID, argsVO.userUID, argsVO.heading, argsVO.message);
			runAsyncTest(token, argsVO, handleSaveBlogPost);
		}
		
		private function handleSaveBlogPost(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			
			newBlogPostUID = message.result as String;
		}
		
		// ----------------------------------------------------------------
		// TEST SAVE BLOG COMMENT
		// ----------------------------------------------------------------
		static private var newBlogPostUID:String;
		
		[Test(async,order=3)]
		public function testSaveBlogComment():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				blogPostUID: newBlogPostUID,
				userUID: "user001",
				message: "This is a test blog comment."
			};
			
			var token:AsyncToken = userProfileService.saveBlogComment(argsVO.sessionID, argsVO.blogPostUID, argsVO.userUID, argsVO.message);
			runAsyncTest(token, argsVO, handleSaveBlogComment);
		}
		
		private function handleSaveBlogComment(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST GET USER PROFILE
		// ----------------------------------------------------------------
		[Test(async,order=4)]
		public function testGetUserProfile():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001"
			};
			
			var token:AsyncToken = userProfileService.getUserProfile(argsVO.sessionID, argsVO.userUID);
			runAsyncTest(token, argsVO, handleGetUserProfile);
		}
		
		private function handleGetUserProfile(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			
			Assert.assertNotNull(message.result.userData);
			Assert.assertNotNull(message.result.status);
			Assert.assertNotNull(message.result.posts);
			
			Assert.assertTrue((message.result.posts.length > 0));
		}
	}
}